package it.unive.taw;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.facebook.android.DialogError;
import com.facebook.android.Facebook;
import com.facebook.android.Facebook.DialogListener;
import com.facebook.android.FacebookError;

public class TAW extends Activity {

	private static Facebook facebook = new Facebook(
			Messages.getString("TAW.facebook"));
	private static String[] PERMISSIONS = new String[] {};

	// { "offline_access",
	// "read_stream", "publish_stream" };

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
	}

	// This method is called at button click because we assigned the name to the
	// "On Click property" of the button
	public void contattiHandler(View view) {
		// switch (view.getId()) {
		// case R.id.contatti_btn:
		startActivity(new Intent(TAW.this, ContattiScreen.class));
		// break;
		// }
	}

	public void facebookHandler(View view) {

		if (!SessionStore.restore(facebook, this)) {
			facebook.authorize(this, PERMISSIONS, new DialogListener() {

				@Override
				public void onFacebookError(FacebookError e) {
					// TODO Auto-generated method stub

				}

				@Override
				public void onError(DialogError e) {
					// TODO Auto-generated method stub

				}

				@Override
				public void onComplete(Bundle values) {
					// TODO Auto-generated method stub

				}

				@Override
				public void onCancel() {
					// TODO Auto-generated method stub

				}
			});
		} else {
			startActivity(new Intent(this, FacebookScreen.class));
		}
	}

	public void mappaHandler(View view) {
		startActivity(new Intent(view.getContext(), Mappa.class));
	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if (requestCode == 32665) {
			facebook.authorizeCallback(requestCode, resultCode, data);
			SessionStore.save(facebook, this);
			startActivity(new Intent(this, FacebookScreen.class));
		}
	}
}